<?php 
	/**
	* 
	*/
class _loginAction extends Action
	{
		/**
		 * display login page 
		 * @return [type] [description]
		 */
		public function index()
		{
			$this->display('index');
		}

		/**
		 * 登陆操作
		 * @return [type] [description]
		 */
		public function login()
		{
			if(!IS_POST) halt("页面不存在！");

			$username = I('username');
			$password = I('password');
			$verify = I('verify', '', 'strtolower');

			if (md5($verify) != session('verify')) {
				$this->error('验证码错误！');
				p($verify);
	  		}

			// 获得用户资料
	    $user = D("User")->selectUserByUsername($username);

	    // 判断密码是否正确
	    if ($user || $user['password'] == encode($password)) {
	      session(C('SESSION_USER_ID'),$user['u_id']);
	      session(C('SESSION_USER_NAME'), $user['username']);
	      
	      $this->success('登陆成功！', U(GROUP_NAME . '/Index/index'));
	    } else {
	      $this->error('登陆失败！');
	    }
		}

		/**
		 * 登出操作
		 * @return [type] [description]
		 */
		public function logout()
		{
			session(C('SESSION_USER_ID'),null);
			session(C('SESSION_USER_NAME'),null);
			$this->success('登出成功！',  U(GROUP_NAME . '/Login/index'));
		}

		/**
		 * 验证码函数
		 * @return [type] [description]
		 */
		public function verify(){
	    import('ORG.Util.Image');
	    Image::buildImageVerify(1, 0);
		    // Image::buildImageVerify('verify');
	  }

	  /**
	   * ajax judge verify is right
	   * @return [type] [description]
	   */
	  public function ajaxVerify()
	  {
	  	if(!IS_POST) halt("Page error!");
	  	$verify = I('verify', '', 'strtolower');
	  	if (md5($verify) == session('verify')) {
	  		// ->ajaxReturn($data,$info,$status,$type)
	  		$this->ajaxReturn(null,"",1);
	  	} else {
	  		$this->ajaxReturn(null,"",0);
	  	}
	  	
	  }
	}
 ?>